package com.alibaba.common;


import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
public class ResponseResult<T> {
    private Integer code;
    private String message;
    private T data;

    private ResponseResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResponseResult<T> error(String message) {
        return new ResponseResult<T>(500, message, null);
    }

    public static <T> ResponseResult<T> error(ResponseEnum enums) {
        return new ResponseResult<T>(enums.getCode(), enums.getMessage(), null);
    }

    public static <T> ResponseResult<T> error(ResponseEnum enums, T data) {
        return new ResponseResult<T>(enums.getCode(), enums.getMessage(), data);
    }

    public static <T> ResponseResult<T> error(Integer code, String message) {
        return new ResponseResult<T>(code, message, null);
    }

    public static <T> ResponseResult<T> ok() {
        return new ResponseResult<T>(ResponseEnum.RESULT_OK.getCode(), ResponseEnum.RESULT_OK.getMessage(),null);
    }

    public static <T> ResponseResult<T> ok(T data) {
        return new ResponseResult<T>(ResponseEnum.RESULT_OK.getCode(), ResponseEnum.RESULT_OK.getMessage(), data);
    }
}
